package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.WormBean;
import com.project.service.WormService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/worm")
public class WormController {

    @Resource
    private WormService wormService;


    //显示所有病害信息
    @RequestMapping("/findAllWorm")
    @ResponseBody
    public IPage<WormBean> findAllWorm(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                       @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return wormService.findAllWorm(pageNo, pageSize);
    }


    //添加新病害
    @RequestMapping("addWorm")
    @ResponseBody
    public String addWorm(WormBean wormBean) {
        wormService.addWorm(wormBean);
        return "ok";
    }


    //查看详细信息
    @RequestMapping("findId")
    @ResponseBody
    public WormBean findId(int wormId) {
        return wormService.findId(wormId);
    }

    //模糊查询
    @RequestMapping("findName")
    @ResponseBody
    public IPage<WormBean> findName(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                    @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                    String wormName, String wormSp) {
        return wormService.findName(pageNo, pageSize, wormName, wormSp);
    }
}
